import nyNetwork from "@/api/nyBaseNetwork";
import DZModelPage from "@/model/DZModelPage";
import DZModelBanner from "../model/DZModelBanner";
import DZModelStoreBanner from "../model/DZModelStoreBanner";

class DZServiceBanner {

    m_page = new DZModelPage(10);

    list_banner: Array<DZModelBanner> = [];

    m_banner = new DZModelBanner();

    list_store_banner: Array<DZModelStoreBanner> = [];

    m_store_banner = new DZModelStoreBanner();

    net_list_banner() {
        var arr_data = [];
        nyNetwork.net("Banner列表", { ...this.m_page }, data => {
            this.m_page.total = data.total;
            for (const item of data.list) {
                var banner = new DZModelBanner();
                banner.id = item.iId ?? '';
                banner.image = item.iImage ?? '';
                if (banner.image) {
                    banner.imageUrl = nyNetwork.image(banner.image)
                }
                banner.type = item.iType ?? 1;
                banner.content = item.iContentId ?? '';
                banner.auth = item.iAuth ?? 0;
                banner.companyList = item.sCompanyList ?? '';
                banner.sort = item.iSort ?? 0 ;
                banner.top = item.iTop ?? 0;
                banner.staffList = item.sStaffList ?? '';
                arr_data.push(banner);
            }
            this.list_banner = arr_data;
        })
    }

    net_add_banner(success: () => void) {
        nyNetwork.net("添加Banner", { ...this.m_banner }, data => {
            success();
        })
    }

    net_edit_banner(success: () => void) {
        nyNetwork.net("编辑Banner", { ...this.m_banner }, data => {
            success();
        })
    }

    net_del_banner(success: () => void) {
        nyNetwork.net("删除Banner", { id: this.m_banner.id }, data => {
            this.m_banner.init();
            success();
        })
    }

    net_edit_sort(id,sort,success: () => void) {
        nyNetwork.net("修改Banner排序", { id: id,sort:sort }, data => {
            success();
        })
    }
    net_edit_store_sort(id,sort,success: () => void) {
        nyNetwork.net("修改商城Banner排序", { id: id,sort:sort }, data => {
            success();
        })
    }
    net_list_store_banner() {
        var arr_data = [];
        nyNetwork.net("商城Banner列表", { ...this.m_page }, data => {
            this.m_page.total = data.total;
            for (const item of data.list) {
                var banner = new DZModelStoreBanner();
                banner.id = item.iid ?? '';
                banner.image = item.iimage ?? '';
                banner.imageUrl = item.iimage ? nyNetwork.image(item.iimage) : '';
                banner.goodsId = item.igoodsId ?? '';
                banner.goodsName = item.sgoodsName ?? '';
                banner.goodsType = item.igoodsType == 1 ? '心理测评' : item.igoodsType == 2 ? '心理咨询' : '';
                banner.sort = item.isort ?? 0;
                banner.top = item.itop ?? 0;
                arr_data.push(banner);
            }
            this.list_store_banner = arr_data;
        })
    }

    net_add_store_banner(success: () => void) {
        delete this.m_store_banner.imageUrl
        nyNetwork.net("添加商城Banner", { ...this.m_store_banner }, data => {
            success();
        })
    }

    net_edit_store_banner(success: () => void) {
        delete this.m_store_banner.imageUrl
        delete this.m_store_banner.goodsName
        delete this.m_store_banner.goodsType
        nyNetwork.net("编辑商城Banner", { ...this.m_store_banner }, data => {
            success();
        })
    }

    net_del_store_banner(success: () => void) {
        nyNetwork.net("删除商城Banner", { id: this.m_store_banner.id }, data => {
            this.m_store_banner = new DZModelStoreBanner();
            success();
        })
    }

    net_move_up(id, success: () => void) {
        nyNetwork.net("Banner数据上移", { id: id }, data => {
            success();
        })
    }
    net_move_down(id, success: () => void) {
        nyNetwork.net("Banner数据下移", { id: id }, data => {
            success();
        })
    }

    net_move_top(id, success: () => void) {
        nyNetwork.net("Banner数据置顶", { id: id }, data => {
            success();
        })
    }

    net_cancel_top(id, success: () => void) {
        nyNetwork.net("Banner取消置顶", { id: id }, data => {
            success();
        })
    }

    net_store_move_up(id, success: () => void) {
        nyNetwork.net("商城Banner数据上移", { id: id }, data => {
            success();
        })
    }
    net_store_move_down(id, success: () => void) {
        nyNetwork.net("商城Banner数据下移", { id: id }, data => {
            success();
        })
    }

    net_store_move_top(id, success: () => void) {
        nyNetwork.net("商城Banner数据置顶", { id: id }, data => {
            success();
        })
    }

    net_store_cancel_top(id, success: () => void) {
        nyNetwork.net("商城Banner取消置顶", { id: id }, data => {
            success();
        })
    }

}
export default DZServiceBanner;